﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Citi.Helpers;
using System.IO;
using Citi.RoutineBase;

namespace Citi.GLCosmos.SchedulerUI
{
    public class Compress : IExecutableRoutine
    {
        public object InitializeLifetimeService()
        {
            return null;
        }
        
        public void Rollback(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            throw new NotImplementedException();
        }

        public void Start(DateTime scheduledDate, ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            ZipFile();
            KillFile();
        }

        public void Stop(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            throw new NotImplementedException();
        }

        public void ZipFile()
        {
            var directory = new DirectoryInfo(@"\\gruvnascti0009.wlb.lac.nsroot.net\data_grp1\ITFMTOOL\ITFMT_GLCOSMOS\PROD\");
            var fileName = directory.GetFiles().OrderByDescending(x => x.LastWriteTime).First();

            var pathFile = string.Concat(directory, fileName);

            FileHelper.Compress(pathFile, @"\\gruvnascti0016.wlb.lac.nsroot.net\DATA_GRP1\FINTOOLS\Tools\I7\GLCosmo\Input\");
        }

        public void KillFile()
        {
            var directory = new DirectoryInfo(@"\\gruvnascti0009.wlb.lac.nsroot.net\data_grp1\ITFMTOOL\ITFMT_GLCOSMOS\PROD\");
            var fileName = directory.GetFiles().OrderByDescending(x => x.LastWriteTime).First();

            string file = string.Concat(directory, fileName);

            if (System.IO.File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.Normal);
                System.IO.File.Delete(file);
            }
        }

        public IEnumerable<RoutineParameter> Parameters
        {
            get { return null; }
        }
    }
}
